package cc.vv.btpartyjob.partymanager.activity

import android.content.Intent
import android.text.TextUtils
import cc.vv.baselibrary.bean.base.BaseResponseObj
import cc.vv.baselibrary.view.BaseTopBarView
import cc.vv.btpartyjob.jnimodule.activity.OrganizationActivity
import cc.vv.btpartyjob.jnimodule.globle.IntentJniKey
import cc.vv.btpartyjob.jnimodule.moudel.resp.OrgDetailResponseObj
import cc.vv.btpartyjob.jnimodule.server.JniDataServer
import cc.vv.btpartyjob.partymanager.delegate.ManagerBaseBinder
import cc.vv.btpartyjob.partymanager.delegate.UnitHouseDetailActivityDelegate
import cc.vv.mvp.activity.BaseActivityMVP
import cc.vv.mvp.binder.BaseDataBinder

/**
 * 组织查询详情
 * Created by Chen.qi on 2018/10/25.
 */
class StreetZuZhiQueryDetailActivity : BaseActivityMVP<UnitHouseDetailActivityDelegate>() {

    override fun initData() {
        viewDelegate?.setTopBarTitle("组织查询")
        val intent = Intent(this@StreetZuZhiQueryDetailActivity, OrganizationActivity::class.java)
        intent.putExtra(IntentJniKey.INTENT_KEY_ORG_TYPE, 1)
        intent.putExtra(IntentJniKey.INTENT_KEY_ORG_CHOOSE, 1)
        startActivityForResult(intent, 100)
    }

    override fun bindEvenListener() {
        viewDelegate?.setTitleBackBtnOnClick(object : BaseTopBarView.EventInterface {
            //返回
            override fun leftOnClick() {
                finish()
            }

            override fun leftCloseClick() {}
            override fun rightOnClick() {
                val intent = Intent(this@StreetZuZhiQueryDetailActivity, OrganizationActivity::class.java)
                intent.putExtra(IntentJniKey.INTENT_KEY_ORG_TYPE, 1)
                intent.putExtra(IntentJniKey.INTENT_KEY_ORG_CHOOSE, 1)
                startActivityForResult(intent, 100)
            }
        })
    }

    override fun getDelegateClass(): Class<UnitHouseDetailActivityDelegate> {
        return UnitHouseDetailActivityDelegate::class.java
    }

    override fun getDataBinder(): BaseDataBinder<*, *> {
        return ManagerBaseBinder()
    }


    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (null == data) {
            finish()
            return
        }
        if (requestCode == 100 && resultCode == 101) {
            val communityId = data.getStringExtra(IntentJniKey.INTENT_KEY_ORGAN_ID)
            if (!TextUtils.isEmpty(communityId)) {
                JniDataServer.getOrganDetail(communityId)
            }
        }
    }

    override fun getData(obj: BaseResponseObj<*>?) {
        super.getData(obj)
        when (obj) {
            is OrgDetailResponseObj -> {
                val data = obj.data
                viewDelegate?.setLouDongUnitName("楼栋名称")
                viewDelegate?.setZhongXinHuName(data?.name)
                viewDelegate?.setZhongXinHuAddress(data?.location)
                viewDelegate?.setLianXiRenName("联系人")
                viewDelegate?.setLianXiRenPhone(data?.mobile)
            }
        }
    }
}